package com.software.sqlite.config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

import java.util.ArrayList;
import java.util.List;

@Configuration
public class MvcInterceptorConfig extends WebMvcConfigurationSupport{

    @Autowired
    private LoginInterceptor loginInterceptor;

    @Override
    protected void addInterceptors(InterceptorRegistry registry) {
        List<String> excludePathPatterns=new ArrayList<>();
        //admin
        excludePathPatterns.add("/");
        excludePathPatterns.add("/MP_verify_CJT1x7zR8dAqTP9A.txt");
        excludePathPatterns.add("/MP_verify_wTlr3d8lHshCLwxm.txt");
        excludePathPatterns.add("/login");
        excludePathPatterns.add("/login");
        excludePathPatterns.add("/page/test");
        excludePathPatterns.add("/page/snmpTest");
        excludePathPatterns.add("/logout");
        excludePathPatterns.add("/index");
        excludePathPatterns.add("/admin/v1/loginInit");
        excludePathPatterns.add("/admin/v1/verifyCode");
        excludePathPatterns.add("/admin/v1/login");
        excludePathPatterns.add("/admin/v1/token");
        excludePathPatterns.add("/admin/v1/init");

        excludePathPatterns.add("/admin/v1/common/curlTest");
        excludePathPatterns.add("/admin/v1/common/snmpTest");
        excludePathPatterns.add("/admin/v1/common/downloadVideo");
        excludePathPatterns.add("/admin/v1/common/showVideo");

        excludePathPatterns.add("/api/**");
        excludePathPatterns.add("/css/**");
        excludePathPatterns.add("/file/**");
        excludePathPatterns.add("/fonts/iconfont/**");
        excludePathPatterns.add("/images/**");
        excludePathPatterns.add("/js/**");
        excludePathPatterns.add("/lib/**");

        //page/apiTest
        excludePathPatterns.add("/page/apiTest");
        excludePathPatterns.add("/admin/v1/common/apiTest");

        //app
        excludePathPatterns.add("/app/v1/login");
        excludePathPatterns.add("/app/v1/verifyCode");
        excludePathPatterns.add("/app/v1/getLastedApp");
        excludePathPatterns.add("/app/v1/addTime");
        excludePathPatterns.add("/app/v1/batchAddTime");
        excludePathPatterns.add("/admin/v1/common/downloadApk");

        excludePathPatterns.add("/movie/v1/verifyCode");
        excludePathPatterns.add("/movie/v1/login");
        excludePathPatterns.add("/movie/v1/register");
        excludePathPatterns.add("/movie/v1/updatePwd");
        excludePathPatterns.add("/movie/v1/movieList");
        excludePathPatterns.add("/movie/v1/movieTypeList");
        excludePathPatterns.add("/movie/v1/showMovieImg");
        excludePathPatterns.add("/movie/v1/showMovieImgBase64");
        excludePathPatterns.add("/movie/v1/myMovie");
        excludePathPatterns.add("/movie/v1/myBill");
        excludePathPatterns.add("/movie/v1/rechargeWallet");
        excludePathPatterns.add("/movie/v1/purchaseMovie");
        excludePathPatterns.add("/movie/v1/getPlayUrl");
        excludePathPatterns.add("/movie/v1/synchronyCloud");

        excludePathPatterns.add("/movie/v1/dangjianList");
        excludePathPatterns.add("/movie/v1/zongyiList");
        excludePathPatterns.add("/movie/v1/myCollect");
        excludePathPatterns.add("/movie/v1/myInfo");
        excludePathPatterns.add("/movie/v1/saveMyCollect");
        excludePathPatterns.add("/movie/v1/myWatch");
        excludePathPatterns.add("/movie/v1/saveMyWatch");
        excludePathPatterns.add("/movie/v1/myBuy");
        excludePathPatterns.add("/movie/v1/myLike");
        excludePathPatterns.add("/movie/v1/saveMyLike");
        excludePathPatterns.add("/movie/v1/showDangjian");
        excludePathPatterns.add("/movie/v1/downloadDangjian");
        excludePathPatterns.add("/movie/v1/showZongyi");
        excludePathPatterns.add("/movie/v1/downloadZongyi");

        excludePathPatterns.add("/movie/v1/flowDataList");
        excludePathPatterns.add("/movie/v1/broadDataList");
        excludePathPatterns.add("/movie/v1/purchaseFlowOrBroadData");

        excludePathPatterns.add("/movie/v1/getSailasTVInfo");



        // 多个拦截器组成一个拦截器链
        // addPathPatterns 用于添加拦截规则，/**表示拦截所有请求
        // excludePathPatterns 用户排除拦截
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns(excludePathPatterns);
        super.addInterceptors(registry);
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //registry.addResourceHandler("/static/*/**").addResourceLocations("classpath:/static/");
        //重写这个方法，映射静态资源文件
        registry.addResourceHandler("/**")
                .addResourceLocations("classpath:/resources/")
                .addResourceLocations("classpath:/static/")
        ;
        super.addResourceHandlers(registry);

    }



}